<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .carousel {
            width: 650px;
            height: 360px;
            margin: 0 auto;
            position: relative;
        }
        
        .carousel ul {
            list-style: none;
        }
        
        .carousel ul li {
            position: absolute;
            top: 0;
            left: 0;
            /* 透明度 */
            opacity: 0;
            transition: opacity 1s ease 0s;
        }
        
        .carousel ul li:first-child {
            opacity: 1;
        }
        
        .carousel .leftbtn {
            display: block;
            position: absolute;
            left: 20px;
            width: 50px;
            height: 50px;
            top: 50%;
            margin-top: -25px;
            background-color: orange;
            border-radius: 50%;
        }
        
        .carousel .rightbtn {
            display: block;
            position: absolute;
            right: 20px;
            width: 50px;
            height: 50px;
            top: 50%;
            margin-top: -25px;
            background-color: orange;
            border-radius: 50%;
        }
    </style>
</head>

<body>
    <div class="carousel">
        <ul id="list">
            <li><img src="D:\BaiduNetdiskDownload\前端体系\images\0.jpg" alt=""></li>
            <li><img src="D:\BaiduNetdiskDownload\前端体系\images\1.jpg" alt=""></li>
            <li><img src="D:\BaiduNetdiskDownload\前端体系\images\2.jpg" alt=""></li>
            <li><img src="D:\BaiduNetdiskDownload\前端体系\images\3.jpg" alt=""></li>
            <li><img src="D:\BaiduNetdiskDownload\前端体系\images\4.jpg" alt=""></li>
        </ul>
        <a href="javascript:;" id="leftbtn" class="leftbtn"></a>
        <a href="javascript:;" id="rightbtn" class="rightbtn"></a>
    </div>
    <script>
        // 得到按钮
        var leftbtn = document.getElementById('leftbtn')
        var rightbtn = document.getElementById('rightbtn')
        var ul = document.getElementById('list')
        var lis = ul.getElementsByTagName('li')
            // 当前ul显示到第几张
        var idx = 0;
        var lock = true;
        // 监听
        rightbtn.onclick = function() {
                if (!lock) return;
                lock = false;
                // 还没改idx之前此时的idx这个图片是老图，淡出
                lis[idx].style.opacity = 0;
                idx++;
                // 改了idx之后此时的idx这个图片就是新图，新图淡入
                if (idx > 4) {
                    idx = 0;
                }
                lis[idx].style.opacity = 1;
                setTimeout(function() {
                    lock = true;
                }, 1000)
            }
            // 左面按钮
        leftbtn.onclick = function() {
            if (!lock) return;
            lock = false;
            // 还没改idx之前此时的idx这个图片是老图，淡出
            lis[idx].style.opacity = 0;
            idx--;
            // 改了idx之后此时的idx这个图片就是新图，新图淡入
            if (idx < 0) {
                idx = 4;
            }
            lis[idx].style.opacity = 1;
            setTimeout(function() {
                lock = true;
            }, 1000)
        }
    </script>
</body>

</html>